﻿using UnityEngine;
using System.Runtime.InteropServices;


/// <summary>
/// 复制到剪贴板
/// </summary>
public class ClipboardManager
{
#if UNITY_IPHONE 
    /* Interface to native implementation */
    [DllImport("__Internal")]
    public static extern void _copyTextToClipboard(string str);
#endif

    public static void CopyToClipboard(string input)
    {
#if UNITY_ANDROID
        // 对Android的调用  
        AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject activity = jc.GetStatic<AndroidJavaObject>("currentActivity");
        if (activity == null)
            return;

        // 复制到剪贴板  
        activity.Call("copyTextToClipboard", input);
#elif UNITY_IPHONE
        //调用clipboard.h中的接口  
        _copyTextToClipboard (input);  
        Debug.LogError ("CopyToClipboard_______"+input);  
#elif UNITY_EDITOR
        TextEditor te = new TextEditor();
        te.content = new GUIContent(input);
        te.OnFocus();
        te.Copy();
#endif
    }
}
